package for_all;

import javax.swing.JOptionPane;

public class PopUp extends javax.swing.JDialog {
    
    public enum MessageTyp {
        Information, Error, Warning;
    }
    
    
    // -------------------------------------------------------------------------
    // Konstruktor mit Titel
    public PopUp(java.awt.Frame parent, String nachricht, String ueberschrift, MessageTyp typ) {
        switch(typ) {
            case Information: showInformation(parent, nachricht, ueberschrift); break;
            case Error: showError(parent, nachricht, ueberschrift); break;
            case Warning: showWarning(parent, nachricht, ueberschrift); break;
        }
    }
    
    
    // -------------------------------------------------------------------------
    // Konstruktor ohne Titel
    public PopUp(java.awt.Frame parent, String nachricht, MessageTyp typ) {
        switch(typ) {
            case Information: showInformation(parent, nachricht, "Hinweis"); break;
            case Error: showError(parent, nachricht, "Fehler"); break;
            case Warning: showWarning(parent, nachricht, "Warnung"); break;
        }
    }
    
    
    // -------------------------------------------------------------------------
    // Hinweis anzeigen (wenn kein Titel und Typ mitgeliefert wird)
    public PopUp(java.awt.Frame parent, String nachricht) {
            showInformation(parent, nachricht, "Hinweis");
    }
    
    
    // -------------------------------------------------------------------------
    // Hinweis anzeigen mit mitgelieferten Titel, ohne Typ
    public PopUp(java.awt.Frame parent, String nachricht, String ueberschrift) {
            showInformation(parent, nachricht, ueberschrift);
    }
   
    
    // -------------------------------------------------------------------------
    // Information anzeigen
    private void showInformation(java.awt.Frame parent, String nachricht, String ueberschrift) {
        JOptionPane.showMessageDialog(parent, nachricht, ueberschrift, JOptionPane.INFORMATION_MESSAGE);
    }
    
    
    // -------------------------------------------------------------------------
    // Fehlermeldung anzeigen
    private void showError(java.awt.Frame parent, String nachricht, String ueberschrift) {
        JOptionPane.showMessageDialog(parent, nachricht, ueberschrift, JOptionPane.ERROR_MESSAGE);
    }
    
    
    // -------------------------------------------------------------------------
    // Warnung anzeigen
    private void showWarning(java.awt.Frame parent, String nachricht, String ueberschrift) {
        JOptionPane.showMessageDialog(parent, nachricht, ueberschrift, JOptionPane.WARNING_MESSAGE);
    }   
        
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(java.awt.Color.lightGray);
        setResizable(false);

        jButton1.setText("ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton1KeyPressed(evt);
            }
        });

        jTextArea1.setEditable(false);
        jTextArea1.setBackground(new java.awt.Color(192, 192, 192));
        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setBorder(null);
        jTextArea1.setDisabledTextColor(new java.awt.Color(204, 204, 204));
        jTextArea1.setFocusable(false);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    //Fehlermeldung schließen mit Enter
    private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
        if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            this.jButton1.doClick();
        }
    }//GEN-LAST:event_jButton1KeyPressed


    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PopUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                PopUp dialog = new PopUp(new javax.swing.JFrame(), "test");
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
}